<?
/**
*  工单管理
*  2013/7/14 by zh
*/
include("../webkit/include/simple_db.php");

require("session.php");
require("xml_excel.php");

$condition = "1=1";
if(isset($_GET['client_name'])) {
	$condition .= " and client_name like '%".$_GET['client_name']."%'";
}
if(isset($_GET['order_status'])) {
	$condition .= " and order_status = ".$_GET['order_status'];
}
if(isset($_GET['telephone'])) {
	$n = $_GET['telephone'];
	$condition .= " and (mobilephone='$n' or telephone1='$n' or telephone2='$n' or telephone3='$n')";
}
if(isset($_GET['user_name'])) {
	$condition .= " and user_name='".$_GET['user_name']."'";
}
if(isset($_GET['agent_name'])) {
	$condition .= " and agent_name='".$_GET['agent_name']."'";
}
if(isset($_GET['callback_result'])) {
	$condition .= " and callback_result=".$_GET['callback_result'];
}
if(isset($_GET['time_range'])) {
	$arr = split("_", $_GET['time_range']);
	$condition .= " and (a.call_time between '".$arr[0]."' and '".$arr[1]."')";
}

$dic_data = array(
		"order_status" => array(1=>"待处理", 2=>"已派单", 3=>"回单", 4=>"改约"),
		"callback_result" => array(1=>"非常满意", 2=>"满意", 3=>'一般', 4=>"不满意"),
		"check_result" => array(1=>"工单完成", 2=>"已处理", 3=>"重派单"),
		"user_called" => array(0=>"未回", 1=>"已回")
); 

$sql = "select a.id, a.order_no, b.client_name,b.mobilephone,a.agent_name,a.call_time,a.user_name, a.expire_time,
a.user_called, a.hasten_count, a.order_status, a.callback_result,a.check_result  
from jx_order a Left Join jx_client b ON a.client_id=b.id where $condition order by id desc"; 

$db = new SimpleDB();
$doc = array();
$db->query($sql);
while($db->next_record()) {
	$doc[] =  array(
			   $db->f("order_no"), 
			   $db->f("client_name"),
			   $db->f("mobilephone"), 
			   $db->f("agent_name"),
			   $db->f("call_time"),
			   $db->f("user_name"),
			   $db->f("expire_time"),
			   $dic_data['user_called'][$db->f("user_called")],
			   $db->f("hasten_count"),
			   $dic_data['order_status'][$db->f("order_status")],
			   $dic_data['callback_result'][$db->f("callback_result")],
			   $dic_data['check_result'][$db->f("check_result")]
	);
}
		
$xml_excel = new Xml_Excel();
$xml_excel->setWorksheetTitle("工单导出结果");
$xml_excel->addArray ( $doc );  
$xml_excel->generateXML ("order_export_".date("YmdHis"));   
?>